from django.db import models
from user.models import UserProfile

class PrivateMessage(models.Model):
    type_options=(("text",'text'),('image','image'),('audio','audio'),('voice','voice'))
    sender = models.ForeignKey(UserProfile, on_delete=models.CASCADE, related_name='sent_messages')
    receiver = models.ForeignKey(UserProfile, on_delete=models.CASCADE, related_name='received_messages')
    content = models.TextField()
    type = models.CharField(choices=type_options, default="text",verbose_name='消息类型',max_length=10)
    timestamp = models.DateTimeField(auto_now_add=True)
    is_read = models.BooleanField(default=False)
    is_received = models.BooleanField(default=False)
    class Meta:
        ordering = ['-timestamp']

# 存放通知消息
class notificationMessage(models.Model):
    receiver = models.ForeignKey(UserProfile, on_delete=models.CASCADE, related_name='receiver_messages')
    content = models.TextField()
    friend=models.ForeignKey(UserProfile, on_delete=models.CASCADE, related_name='friend_messages',null=True,blank=True)
    is_received=models.BooleanField(default=False,verbose_name="是否接收")
    timestamp = models.DateTimeField(auto_now_add=True)
    is_read=models.BooleanField(default=False,verbose_name="是否已读")
    class Meta:
        ordering = ['-timestamp']